<?php
class TopicAction extends BaseAction {
	public function index(){
		
		$id = $_GET['id'];
		$Topic = D('Topic')->find($id);
		
		$Article = D("Article");
		
		import("ORG.Util.Page");
		
		$map['tid']=$id;
		$list = $Article->findAll($map,'*','id desc','');
		
		$count = $Article->count($data);
		$listRows=10;
		$p=new page($count,$listRows);
		$list=$Article->findAll($data,'*','id desc',$p->firstRow.','.$p->listRows);
		$page  = $p->show();
		/**/
		if ($list!==false) {
			$this->assign('page',$page);
			$this->assign('articles',$list);
			$this->assign('topic', $Topic);
		}
		
		$this->display();
	}
	
	public function post(){
		
		$tid = $_GET['id'];
		$uid = Session::get(C('USER_AUTH_KEY'));
		if($uid===NULL){
			$this->error(L("没有登录"));
		}
		$this->assign('uid',$uid);
		$this->assign('tid',$tid);
		$this->assign('returnUrl','index/id/'.$tid);
//		dump('uid/'.$uid);
		$this->display();
	}
	
	public function newpost(){
		
		$data=$_POST;
		$Article=D("Article");
        if($Article->create()) {
        	$Article->postdate = time(); 
            if($Article->add()){
            	$this->assign('jumpUrl', $data['returnUrl']);
				$this->success(L('_INSERT_SUCCESS_'));
            }else{ 
                $this->error(L(_INSERT_FAIL_));
            } 
        }else{ 
            $this->error($User->getError()); 
        }
	}
	
	function searchTopic(){
    	$id = $_GET['id'];
    	$Topic = D("Topic");
		$topic = $Topic->find($id);
    	exit( json_encode($topic));
    }
}
?>